package com.hvgroup.modules.sanic.websocket;

import com.hvgroup.modules.sanic.domain.enums.DiFyAppEnum;
import com.hvgroup.utils.SecurityUtils;
import lombok.*;

import java.util.Map;

@ToString
@Builder
@Getter
public class QASocketQuery {
    private final String chatId;
    private final String userId;
    private final String message;
    private final DiFyAppEnum qaType;

    public static QASocketQuery buildToMap(Map<String, Object> body, String message){
        String chatId = String.valueOf(body.get("chatId"));
        String userId = String.valueOf(SecurityUtils.getCurrentUserId());
        String query = body.get("query").toString();
        DiFyAppEnum qaType = DiFyAppEnum.valueOf(String.valueOf(body.get("qaType")));

        return QASocketQuery.builder()
                .chatId(chatId)
                .userId(userId)
                .message(query)
                .qaType(qaType)
                .build();
    }

    public static QASocketQuery buildToQuery(QASocketQuery query, String message){

        return QASocketQuery.builder()
                .chatId(query.getChatId())
                .userId(query.getUserId())
                .qaType(query.getQaType())
                .message(message)
                .build();
    }
}
